package rmi.attempt1.client;

import rmi.attempt1.net.*;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Client {

	public static final void main(String[] args) throws Exception {
		final int port = 40004;
		final String BIND_ADDRESSE = "eventHandler";
		Registry rmiregistry = LocateRegistry.getRegistry("localhost", port);
		EventHandler eh = (EventHandler) rmiregistry.lookup(BIND_ADDRESSE);
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		System.out.print("Please type a name: ");
		String username = in.readLine();
		ClientChatEventListener l = new ClientChatEventListener(username);
		eh.addChatEventListener(l);
		String message = "";
		do {
			message = in.readLine();
			if (!"".equals(message)) {
				eh.dispatchChatMessage(username, message);
			}
		} while (!"".equals(message));
		eh.removeChatEventListener(l);
	}

}
